package com.hyf.translucentstatusbar.base;

import android.view.View;
import android.widget.ImageView;

import com.hyf.translucentstatusbar.R;

/**
 * Created by Administrator on 2017/9/13.
 */

/**
 * @deprecated 该类已被废除 请使用
 * {@link BaseActivity }
 */
@Deprecated
public abstract class BaseHeaderActivity extends BaseAbstractActivity implements OnScrollListener {

    private ImageView toolBarImage;

    // 滑动多少距离后标题不透明
    private int slidingDistance;

    @Override
    public void setContentView(View view) {
        super.setContentView(view);
        toolBarImage = (ImageView) findViewById(R.id.hyf_iv_title_bar);
        initTitleBar();
        slidingDistance = setHeaderView().getLayoutParams().height - (getStatusBarHeight() + toolBar.getLayoutParams().height);
    }

    private void initTitleBar() {
        setHeaderBarAlpha(0);
    }

    protected abstract View setHeaderView();

    @Override
    protected Object setDefaultHeaderImage() {
        return "http://n.sinaimg.cn/crawl/20150702/5G8w-fxesfuc3480710.png";
    }

    @Override
    public void onScrollChange(int scrollY) {
        if (slidingDistance <= 0) return;
        if (scrollY < 0) {
            scrollY = 0;
        }
        float alpha = (float) scrollY / (float) slidingDistance;
        if (scrollY <= slidingDistance) {
            setHeaderBarAlpha((int) (255 * alpha));
        } else {
            setHeaderBarAlpha(255);
        }
    }
}
